package com.xja.seckill.order.controller;

import com.xja.seckill.order.commons.JsonBean;
import com.xja.seckill.order.ProductCilentApi;
import com.xja.seckill.order.rabbitmq.RabbitMQOrderSend;
import com.xja.seckill.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private ProductCilentApi productCilentApi;

    @Autowired
    private OrderService orderService;

    @Autowired
    private RabbitMQOrderSend rabbitMQOrderSend;

    @RequestMapping("getOrderInfo")
    public JsonBean getOrderInfo(Integer id) {
        return productCilentApi.getProductById (id);
    }

    @RequestMapping("createOrder")
    public JsonBean createOrder(Integer userId,Integer skuId) {
        if (userId==null || skuId==null){
            return new JsonBean (0,"参数不足",null);
        }
        return orderService.createOrder (userId,skuId);
    }

    @RequestMapping("rabbitmq")
    public JsonBean rabbitmq(Integer userId,Integer skuId) {
        rabbitMQOrderSend.sendOrder2 ();
        return new JsonBean (0,"ok",null);
    }


    @RequestMapping("payOrder")
    public JsonBean payOrder( String code) {
        orderService.payOrder (code);
        return new JsonBean (0,"ok",null);
    }


}
